package com.wavercaz.freeforum.utils;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class ResponseResult {
    private Integer code;
    private String message;
    private Object data;

    public ResponseResult(Integer code) {
        this.code = code;
    }

    public ResponseResult(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResponseResult(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResponseResult(Integer code, Object data) {
        this.code = code;
        this.data = data;
    }

    public Object getData() {
        if(data instanceof Page){
            Map<String,Object> res=new HashMap<>();
            Page page= (Page) data;
            res.put("list",page.getRecords());
            res.put("total",page.getTotal());
            res.put("page",page.getPages());
            res.put("current",page.getCurrent());
            data=res;
        }
        return data;
    }
}
